package battleship;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import battleship.FBConstants;

/**
 * Servlet implementation class authent
 */
@WebServlet("/authent")
public class authent extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public authent() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String state = String.valueOf(Math.random());
		request.getSession().setAttribute("FBState", state);
		
		// pane paika veel mõned andmed, mida JSP lehel kasutada
		request.getSession().setAttribute("FBRedirect", FBConstants.REDIRECT_URI);
		request.getSession().setAttribute("FBAppID", FBConstants.APP_ID);
		response.setContentType("text/html");
		// esita sisselogimisleht JSP abil
		//request.getRequestDispatcher("login.jsp").forward(request, response);
		RequestDispatcher rd = getServletContext().getRequestDispatcher("/login.jsp");
        rd.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
